<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
	<xsl:include href="../../admin.xsl" />
	<xsl:include href="../../cp/path.xsl" />
	
	<!-- Запускаем рендер страницы -->
	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/admin/modules.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/admin/modules.js" />
		</head>
		<body>
			<xsl:call-template name="admin-header" />
			
			<div id="blocks">
				<div id="blocks_inner" />
			</div>
			
			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>
			
			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	<xsl:template match="response">		
		<div id="path">
			<xsl:apply-templates select="document('xmodule://cp/getPath/0;system;modules')/data/response" mode="cp-path" />
		</div>
		
		<h1>Модули</h1>
		
		<xsl:apply-templates select="message" />
		
		<p>
			<a class="install" href="{$baseURI}/admin/system/modules" onclick="showModuleInstallDialog(); return false;">Установить</a>
			<xsl:text disable-output-escaping="yes">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;</xsl:text>
			<a class="add" href="{$baseURI}/admin/system/create_module">Создать модуль</a>
		</p>
		
		<table class="standart modules" cellspacing="0" cellpadding="0">
			<tbody>
				<tr>
					<th />
					<th>Название</th>
					<th>Описание</th>
					<th>Опции</th>
				</tr>
				<xsl:apply-templates select="object[@type='explay_module']" />
			</tbody>
		</table>
	</xsl:template>
	
	<xsl:template match="object[@type='explay_module']">
		<xsl:param name="avatar" select="property[@name='avatar']/value" />
		<xsl:param name="authorURI" select="property[@name='author_uri']/value" />
		<xsl:param name="pageURI" select="property[@name='page_uri']/value" />
		
		<tr>
			<td>
				<img>
					<xsl:attribute name="src">
						<xsl:if test="$avatar = ''">
							<xsl:value-of select="concat($baseURI, '/images/admin/default-module-avatar.png')" />
						</xsl:if>
						<xsl:if test="$avatar != ''">
							<xsl:value-of select="concat($baseURI, $avatar)" />
						</xsl:if>
					</xsl:attribute>
				</img>
			</td>
			<td>
				<xsl:value-of select="property[@name='title']/value" />
			</td>
			<td>
				<div class="description">
					<xsl:value-of select="property[@name='description']/value" />
				</div>
				<div class="info">
					<xsl:text>версия: </xsl:text>
					<b><xsl:value-of select="property[@name='version']/value" /></b>
					<xsl:text> | </xsl:text>
					<xsl:text>разработчик: </xsl:text>
					
					<xsl:if test="$authorURI = ''">
						<xsl:value-of select="property[@name='author_name']/value" />
					</xsl:if>
					
					<xsl:if test="$authorURI != ''">
						<a href="{$authorURI}">
							<xsl:value-of select="property[@name='author_name']/value" />
						</a>
					</xsl:if>
					
					<xsl:if test="$pageURI != ''">
						<xsl:text> | </xsl:text>						
						<a href="{$pageURI}">
							<xsl:text>страница модуля</xsl:text>
						</a>
					</xsl:if>
				</div>
			</td>
			<td>
				<xsl:if test="property[@name='my']/value = 1">
					<a href="{$baseURI}/admin/system/module_export/{@id}">Экспортировать</a>
					<xsl:text> ∙ </xsl:text>
					<a href="{$baseURI}/admin/system/edit_module/{@id}">Редактировать</a>
					<xsl:text> ∙ </xsl:text>
				</xsl:if>
				<a href="{$baseURI}/admin/system/delete_module/{@id}">Удалить</a>
			</td>
		</tr>
	</xsl:template>
	
</xsl:stylesheet>